<?php
header("content-type:text/html;charset=utf8");
include_once ("/Classes/PHPExcel.php");
$pdo = new PDO("mysql:host=127.0.0.1;dbname=07c;charset=utf8",'root','root');
$sql = "select * from user";
$res = $pdo->query($sql);
$data = $res->fetchAll(PDO::FETCH_ASSOC);
// print_r($data);die;
$excel = new PHPExcel();
$sheet = $excel->setActiveSheetIndex(0);
$sheet ->setCellValue('A1','ID')
       ->setCellValue('B1','name')
       ->setCellValue('C1','pwd');
       $i = 2;
       foreach ($data as $k => $v)
       {
       	$sheet ->setCellValue('A'.$i,$v['id'])
               ->setCellValue('B'.$i,$v['name'])
               ->setCellValue('C'.$i,$v['pwd']);
       	$i++;
       }

header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="01simple.xls"');
header('Cache-Control: max-age=0');


$objWriter = PHPExcel_IOFactory::createWriter($excel, 'Excel5');
$objWriter->save('php://output');
exit;   
?>